package cn.ydt.ydt.admin.webapi.controller;

import cn.ydt.ydt.admin.service.INetService;
import cn.ydt.ydt.common.resful.JsonResult;
import cn.ydt.ydt.pojo.admin.dto.AddNetDTO;
import cn.ydt.ydt.pojo.admin.dto.UpdateNetDTO;
import cn.ydt.ydt.pojo.admin.model.Net;
import cn.ydt.ydt.pojo.admin.vo.SimpleNetLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.client.license.LicensesStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "网格员相关接口")
@RestController
@RequestMapping("/net")
public class NetController {

    @Autowired
    INetService netService;


    @ApiOperation("网格员登录时信息获取")
    @GetMapping("/login/info")
    public JsonResult<SimpleNetLoginVO> getNetSimple(){
        SimpleNetLoginVO simpleNetLoginVO = netService.getSimpleNetById();
        return JsonResult.ok(simpleNetLoginVO,"查询成功");
    }

    @ApiOperation("添加网格员")
    @PostMapping("/add")
    public JsonResult<Void> addNet(@RequestBody AddNetDTO addNetDTO){
        netService.addNet(addNetDTO);
        return JsonResult.ok("添加成功！");
    }

    @ApiOperation("修改网格员信息")
    @PostMapping("/update")
    public JsonResult<Void> updateNet(@RequestBody UpdateNetDTO updateNetDTO){
        netService.updateNet(updateNetDTO);
        return JsonResult.ok("修改成功");
    }


    @ApiOperation("获取本社区网格员列表")
    @GetMapping("/get/netList")
    public JsonResult<List<Net>> getNetList(){
        List<Net> netList = netService.getNetList();
        return JsonResult.ok(netList);
    }

    @ApiOperation("根据姓名查询网格员信息")
    @GetMapping("/get/{name}")
    public JsonResult<Net> getNetByName(@PathVariable String name){
        Net net = netService.getNetByName(name);
        return JsonResult.ok(net);
    }

    @ApiOperation("查询社区的网格员姓名")
    @GetMapping("/get/name")
    public JsonResult<List<String>> getNameById(){
        List<String> names = netService.getNameByCommunityId();
        return JsonResult.ok(names);
    }

}
